package cn.wolfcode.crm.util;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.StudentAccount;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 获取当前登陆用户
 */
public abstract class UserContext {

    /**
     * 获取当前用户
     * @return
     */
    public static Employee getUserContext(){
        Subject subject = SecurityUtils.getSubject();
        Employee principal = (Employee) subject.getPrincipal();
        return principal;
    }

    /**
     * 获取当前登陆的学生用户
     * @return
     */
    public static StudentAccount getStudentContext(){
        Subject subject = SecurityUtils.getSubject();
        StudentAccount principal = (StudentAccount) subject.getPrincipal();
        return principal;
    }

    /**
     * 获取当前的请求
     * @return
     */
    public static HttpServletRequest getRequest(){
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).
                getRequest();
    }
}
